package guice

import javax.inject.Inject

import org.quartz.{Job, Scheduler, SchedulerException}
import org.quartz.spi.{JobFactory, TriggerFiredBundle}
import play.api.inject.Injector

/**
  * Created by fanqiang on 17/3/31.
  */
class ElementalJobFactory @Inject()(injector: Injector) extends JobFactory {

  override def newJob(triggerFiredBundle: TriggerFiredBundle, scheduler: Scheduler): Job =
    try {
      injector.instanceOf(triggerFiredBundle.getJobDetail().getJobClass())
    } catch {
      case e: Exception => throw new SchedulerException(e);
    }
}
